package l5;

import l3.LinkedList;

import java.util.Scanner;

public class test {

    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("请选择集合类型：");
        System.out.println("1. 顺序表");
        System.out.println("2. 单链表");

        int choice = sc.nextInt();
        switch (choice) {
            case 1: {
                ArrayStack stack = new ArrayStack();
                System.out.println("\n请选择操作：");
                System.out.println("0. 退出程序");
                System.out.println("1. 插入");
                System.out.println("2. 删除");
                System.out.println("3. 查找头元素");
                System.out.println("4. 获取大小");
                System.out.println("5. 判断集合是否为空");
                while (true) {
                    System.out.print("\n请输入操作编号: ");
                    int operation = sc.nextInt();
                    switch (operation) {
                        case 0:
                            System.out.println("程序退出！");
                            System.exit(0);
                            break;
                        case 1:
                            System.out.println("请输入插入元素");
                            stack.push(sc.nextInt());
                            break;
                        case 2:
                            System.out.println("删除"+stack.peek()+"成功");
                            stack.pop();
                            break;
                        case 3:
                            System.out.println("头元素为"+stack.peek());
                            break;
                        case 4:
                            System.out.println("大小为："+stack.size());
                            break;
                        case 5:
                            System.out.println("是否为空："+stack.isEmpty());
                            break;
                    }
                }
            }
            case 2: {
                LinkedStack stack = new LinkedStack();
                System.out.println("\n请选择操作：");
                System.out.println("0. 退出程序");
                System.out.println("1. 插入");
                System.out.println("2. 删除");
                System.out.println("3. 查找头元素");
                System.out.println("4. 获取大小");
                System.out.println("5. 判断集合是否为空");
                while (true) {
                    System.out.print("\n请输入操作编号: ");
                    int operation = sc.nextInt();
                    switch (operation) {
                        case 0:
                            System.out.println("程序退出！");
                            System.exit(0);
                            break;
                        case 1:
                            System.out.println("请输入插入元素");
                            stack.push(sc.nextInt());
                            break;
                        case 2:
                            System.out.println("删除"+stack.peek()+"成功");
                            stack.pop();
                            break;
                        case 3:
                            System.out.println("头元素为"+stack.peek());
                            break;
                        case 4:
                            System.out.println("大小为："+stack.size());
                            break;
                        case 5:
                            System.out.println("是否为空："+stack.isEmpty());
                            break;
                    }
                }
            }
        }
    }
}

